#!/bin/bash
set -e

TMP=${TMP:-/tmp/work}
LOG=${LOG:-$HOME/logs/stage1}
SRC=${SRC:-$LFS/sources}

name=file
version=5.39

rm -fr $TMP
mkdir -pv $TMP $LOG

tar xf $SRC/$name-$version.tar.gz -C $TMP

{ time \
   {
    
    cd $TMP/$name-$version

    mkdir build
    pushd build
        ../configure --disable-bzlib      \
                    --disable-libseccomp \
                    --disable-xzlib      \
                    --disable-zlib
        make
    popd

    ./configure --prefix=/usr --host=$LFS_TGT --build=$(./config.guess)

    make FILE_COMPILE=$(pwd)/build/src/file
    
    make DESTDIR=$LFS install

    }
} 2>&1 | tee $name.log

[ $PIPESTATUS = 0 ] && mv $name.log $LOG || exit $PIPESTATUS

rm -fr $TMP
